import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { dictItemCheck } from './dict.api';
import { rules } from '/@/utils/helper/validator';
import { h } from 'vue';
import { getSingersAllList } from '../projectVote/projectVote.api';

export const columns: BasicColumn[] = [
  {
    title: '歌手',
    dataIndex: 'singer',
    customRender: ({ record }) => {
      if (record && record.singer && record.singer.name) {
        return h('div', { innerText: record.singer.name });
      } else {
        return null; // 或者你想要显示的默认内容
      }
    },
  },
  {
    title: '评论内容',
    dataIndex: 'content',
  },
  {
    title: '审批',
    dataIndex: 'approved',
    format: (v) => {
      return v == '0' ? '同意' : '不同意';
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '歌手',
    field: 'singerId',

    component: 'ApiSelect',
    componentProps: {
      api: getSingersAllList,
      labelField: 'name',
      valueField: 'id',
    },
    colProps: { span: 6 },
  },
  {
    label: '评论内容',
    field: 'content',
    component: 'InputTextArea',
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '歌手',
    field: 'singerId',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: getSingersAllList,
      labelField: 'name',
      valueField: 'id',
    },
  },
  {
    label: '评论内容',
    field: 'content',
    component: 'Input',
  },
  {
    field: 'approved',
    label: '审批',
    defaultValue: 1,
    component: 'JDictSelectTag',
    componentProps: {
      type: 'radioButton',
      dictCode: 'approvalStatus',
      stringToNumber: false,
    },
  },
];

export const dictItemColumns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'itemText',
    width: 80,
  },
  {
    title: '数据值',
    dataIndex: 'itemValue',
    width: 80,
  },
  {
    title: '字典颜色',
    dataIndex: 'itemColor',
    width: 80,
    align: 'center',
    customRender: ({ text }) => {
      return h('div', {
        style: { background: text, width: '18px', height: '18px', 'border-radius': '50%', margin: '0 auto' },
      });
    },
  },
];

export const dictItemSearchFormSchema: FormSchema[] = [
  {
    label: '名称',
    field: 'itemText',
    component: 'Input',
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'dict_item_status',
      stringToNumber: true,
    },
  },
];

export const itemFormSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '名称',
    field: 'itemText',
    required: true,
    component: 'Input',
  },
  {
    label: '数据值',
    field: 'itemValue',
    component: 'Input',
  },
  {
    label: '颜色值',
    field: 'itemColor',
    component: 'Input',
    slot: 'itemColor',
  },
  {
    label: '描述',
    field: 'description',
    component: 'Input',
  },
  {
    field: 'sortOrder',
    label: '排序',
    component: 'InputNumber',
    defaultValue: 1,
  },
  {
    field: 'status',
    label: '是否启用',
    defaultValue: 1,
    component: 'JDictSelectTag',
    componentProps: {
      type: 'radioButton',
      dictCode: 'dict_item_status',
      stringToNumber: true,
    },
  },
];
